<?php

namespace App\Console\Commands;

use App\Imports\MultipleImport;
use App\Models\JobType;
use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;

class AddJobType extends Command
{
    /**
     * 导入工种
     * The name and signature of the console command.
     * php artisan command:addjobtype
     * @var string
     */
    protected $signature = 'command:addjobtype';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $file = public_path('excel').'/工种.xlsx';//获取文件路径
        $import = new MultipleImport(3);
        Excel::import($import, $file);
        $results = $import->sheet[0]->data->toArray();
        //$results2 = $import->sheet[1]->data->toArray();
        //$results3 = $import->sheet[2]->data->toArray();
        //dd($results,$results2,$results3);
        unset($results[0]);
        unset($results[1]);
        foreach($results as $k=>$v){
            $this->info('导入：工种='.$v[1]);
            $job_obj = JobType::updateOrCreate(['job_type'=>$v[1]],['job_type'=>$v[1]]);
        }
    }
}
